<?php
//insert_days_visits  //根据日期段添加企业站日访问量
//按日期添加点击量，有记录则修改小于150的点击量
header('Content-Type:text/html;charset=utf8');
include_once './db.php';
include_once './function.php';
$db = DB::getIntance();
$db_table = 'days_visits';

$cpid = (int)$_GET['cpid'];
$start_date = $_GET['start_date'];
$end_date = $_GET['end_date'];

if (!$cpid || !$start_date) {
    echo json_encode(array('code' => 0, 'msg' => '缺少参数', 'data' => '',));
    exit();
}

$date_arr = getDateFromRange($start_date, $end_date);
if (empty($date_arr)) {
    echo json_encode(array('code' => 0, 'msg' => '日期错误', 'data' => '',));
    exit();
}

foreach ($date_arr as $value) {
    insert_visit($cpid, $value);
}

echo json_encode(array('code' => 1, 'msg' => '添加成功', 'data' => ''));